
/**
 * 
 * The Activity object contains all the data associated with doing something on a planet or in space.
 *
 */
public class Activity extends BaphiListItem {
	
	enum Type { Standard, Combat, EnabledLanding, Landing, TakeOff, Error };

	private int planet;
	private Type type;
	private String description;
	private int phaseCost;
	private boolean enabled[];
	private int reading;
	private ResultList results;
	
	/**
	 * The Activity object contains all the data associated with doing something on a planet or in space. This constructor should only be called for a Combat activity.
	 * @param name - Unique name
	 * @param planet - index into Planet list
	 * @param numPlayers - number of players
	 */
	public Activity(String name, int planet, int numPlayers)
	{
		this.name = name;
		this.planet = planet;
		type = Type.Combat;
		enabled = new boolean[numPlayers];
		results = new ResultList();
	}
	
	/**
	 * The Activity object contains all the data associated with doing something on a planet or in space. This constructor should be called for all non-combat activities.
	 * @param name - Unique name
	 * @param planet - index of Planet where this activity occurs (or 0 if in space)
	 * @param type - activity type
	 * @param description - Human-readable activity name
	 * @param phaseCost - number of phases it takes to perform this action
	 * @param reading - passage number for this activity
	 * @param numPlayers - number of players
	 */
	public Activity(String name, int planet, Type type, String description, int phaseCost, int reading, int numPlayers)
	{
		this.name = name;
		this.planet = planet;
		this.type = type;
		this.description = description;
		this.phaseCost = phaseCost;
		this.reading = reading;
		enabled = new boolean[numPlayers];
		results = new ResultList();
	}

	/**
	 * 
	 * @return index of planet where this activity occurs (or 0 if in space)
	 */
	public int getPlanet()
	{
		return planet;
	}
	
	/**
	 * 
	 * @return activity type
	 */
	public Type getType()
	{
		return type;
	}
	
	/**
	 * 
	 * @param type - activity type
	 */
	public void setType(Type type)
	{
		this.type = type;
	}
	
	/**
	 * 
	 * @return Human-readable activity name
	 */
	public String getDescription()
	{
		return description;
	}
	
	/**
	 * 
	 * @return Number of phases the activity takes to perform
	 */
	public int getPhaseCost()
	{
		return phaseCost;
	}
	
	/**
	 * 
	 * @param playerNum
	 * @return True if the activity is enabled for the player number
	 */
	public boolean isEnabled(int playerNum)
	{
		return enabled[playerNum];
	}
	
	/**
	 * Enables this activity for all players
	 */
	public void enableForAll()
	{
		for (int i = 0; i < enabled.length; i++)
			enabled[i] = true;
	}
	
	/**
	 * 
	 * @return Passage number for the player to read
	 */
	public int getReading()
	{
		return reading;
	}
	
	/**
	 * Adds a result to the Activity's ResultList.
	 * @param r - Result object to add
	 */
	public void addResult(Result r)
	{
		results.add(r);
	}

	/**
	 * 
	 * @param idx - offset into ResultList
	 * @return Result
	 */
	public Result getResult(int idx)
	{
		return results.get(idx);
	}
}
